package com.sinosoft.cloud.access.net;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2017-10-25.
 */
@Component
public class AccessControl {

    /**
     * 读取配置文件，获取发生熔断机制的阈值
     */
    @Value("${persist.max.count}")
    private Integer threshold;

    /**
     * 密文持久化开关
     */
    @Value("${cloud.access.abc.save.cipher.open}")
    private Boolean cipherTextSwitch;

    /**
     * 明文持久化开关
     */
    @Value("${cloud.access.abc.save.clear.open}")
    private Boolean clearTextSwitch;

    /**
     * 返回明文持久化开关
     */
    @Value("${cloud.access.abc.save.clearOut.open}")
    private Boolean outClearTextSwitch;

    /**
     * 调用微服务超时时间
     */
    @Value("${ribbon.ReadTimeout}")
    private long readTimeout;

    /**
     * 挡板开关，用于测试
     */
    @Value("${cloud.access.barrier.control}")
    private Boolean barrier;

    private String updateContNoFlag = "on";

    /**
     * cip返回超时时间
     */
    @Value("${CipReturn.TimeOut}")
    private long CipReturnTimeOut;

    public Integer getThreshold() {
        return threshold;
    }

    public void setThreshold(Integer threshold) {
        this.threshold = threshold;
    }

    public Boolean getCipherTextSwitch() {
        return cipherTextSwitch;
    }

    public void setCipherTextSwitch(Boolean cipherTextSwitch) {
        this.cipherTextSwitch = cipherTextSwitch;
    }

    public Boolean getClearTextSwitch() {
        return clearTextSwitch;
    }

    public void setClearTextSwitch(Boolean clearTextSwitch) {
        this.clearTextSwitch = clearTextSwitch;
    }

    public Boolean getOutClearTextSwitch() {
        return outClearTextSwitch;
    }

    public void setOutClearTextSwitch(Boolean outClearTextSwitch) {
        this.outClearTextSwitch = outClearTextSwitch;
    }

    public Boolean getBarrier() {
        return barrier;
    }

    public void setBarrier(Boolean barrier) {
        this.barrier = barrier;
    }

    public long getCipReturnTimeOut() {
        return CipReturnTimeOut;
    }

    public void setCipReturnTimeOut(long cipReturnTimeOut) {
        CipReturnTimeOut = cipReturnTimeOut;
    }

    public long getReadTimeout() {
        return readTimeout;
    }

    public void setReadTimeout(long readTimeout) {
        this.readTimeout = readTimeout;
    }

    /**
     * 若开启挡板开关，则不走服务路由，不进行报文持久化，不调用任何微服务
     * @return
     */
    public Boolean getBarrierControl(){
        if (this.barrier){
            this.cipherTextSwitch = false;
            this.clearTextSwitch = false;
            this.outClearTextSwitch = false;
            return true;
        }
        return false;
    }

    public String getUpdateContNoFlag() {
        return updateContNoFlag;
    }

    public void setUpdateContNoFlag(String updateContNoFlag) {
        this.updateContNoFlag = updateContNoFlag;
    }
}
